package com.efast.dmom.aps.bean.base;

import java.io.Serializable;
import java.time.ZonedDateTime;

import com.efast.dmom.aps.datahandlers.DataHandlerUtils;
import com.efast.dmom.aps.entity.base.BaseEntity;

public abstract class Bean<T extends BaseEntity> implements Serializable{
	
	private static final long serialVersionUID = 7320200123369440276L;
	protected T baseEntity = null;

	private short modificationFlag ;
	
	protected Bean() {
		super();
//		init();
	}
	private void init() {
//		private long id;
//		private String name;
//		private String description;
//		private int siteId;
//		private LocalDateTime creationTime;
//		private String creationTimeZone;
//		private String creator;
//		private LocalDateTime lastModifiedTime;
//		private String lastModifiedTimeZone;
//		private String lastModifier;
//		private int creationPid;
//		private int lastModifiedPid;
//		private int rowStatus;
//		private long rowTrxId;
		
//		ZonedDateTime now = ZonedDateTime.now();
		
		//this.baseEntity.setId(DataHandlerUtils.getDmomId());
//		this.baseEntity.setName("");
//		this.baseEntity.setDescription("");
//		this.baseEntity.setSiteId(DataHandlerUtils.getSiteId());
//		this.baseEntity.setCreationTime(now.toLocalDateTime());
//		this.baseEntity.setCreationTimeZone(now.getZone().toString());
//		this.baseEntity.setCreator("");
//		this.baseEntity.setLastModifiedTime(now.toLocalDateTime());
//		this.baseEntity.setLastModifiedTimeZone(now.getZone().toString());
//		this.baseEntity.setLastModifier("");
//		this.baseEntity.setCreationPid(DataHandlerUtils.getDmomPid());
//		this.baseEntity.setLastModifiedPid(DataHandlerUtils.getDmomPid());
//		this.baseEntity.setRowStatus(1);
		//this.baseEntity.setRowTrxId(111); 未实现
		
	}
	public Bean(T baseEntity) {
		this.baseEntity = baseEntity;
	}

	public T getInnerEntity() {
		return baseEntity;
	}
	public void setInnerEntity(T innerEntiry) {
		this.baseEntity = innerEntiry;
	}

	protected void initialize(T baseEntity) {

		if (baseEntity == null) {
			throw new IllegalArgumentException("Null data object is not allowed");
		}
	}

	

	public void setName(String name) {
		this.baseEntity.setName(name);
	}

	public String toString() {
		return this.baseEntity.toString();
	}
	
	public boolean equals(Object obj) {

		boolean result = false;

		if (obj == null) {
			return result;
		}

		if (getInnerEntity().getId() <= 0) {
			result = (this == obj);
		} else {
			if(obj instanceof Bean) {
				result = (this.getInnerEntity().getId() == ((Bean<?>)obj).getInnerEntity().getId());
			}
		}
		
		return result;
	}
	public short getModificationFlag() {
		return modificationFlag;
	}
	public void setModificationFlag(short modificationFlag) {
		this.modificationFlag = modificationFlag;
	}
}
